package com.hspedu.method;

/**
 * @author LiuJinTao
 * @className ThreadMethodExercise
 * @date 2024/06/23 17:03
 * @description TODO
 */
public class ThreadMethodExercise {
    public static void main(String[] args) throws InterruptedException {
        for (int i = 1; i <= 10; i++) {
            System.out.println("hi " + i);
            Thread.sleep(1000);
            if (i == 5) {
                T2 t2 = new T2();
                t2.start();
                t2.join();
                System.out.println("子线程结束");
            }
        }
    }
}

class T2 extends Thread {
    @Override
    public void run() {
        for (int i = 1; i <= 10; i++) {
            System.out.println("hello " + i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

        }
    }
}